<template>
  <view class="whole">
    <u-toast ref="uToast" />

    <view class="notice">企业名称：</view>
    <view class="bootm">
      <input
        class="modal-input"
        type="text"
        v-model="company_name"
        disabled
        placeholder="填写企业名称"
        placeholder-style="font-size:32rpx"
        style="font-size: 32rpx"
      />
    </view>

    <view class="upload">
      <view style="padding: 25rpx 20rpx; font-size: 32rpx; color: #bbbbbe">
        <text
          >上传logo ({{
            company_logo.length > 1 ? 1 : company_logo.length
          }}/1)</text
        >
      </view>
      <view class="upload_upload">
        <view class="" style="display: flex">
          <view
            v-for="(item, index) in company_logo"
            v-if="company_logo.length != 0"
            style="
              display: flex;
              justify-content: space-between;
              position: relative;
            "
          >
            <image
              :src="item"
              @click="remove(index, 'company_logo')"
              mode=""
              style="width: 170rpx; height: 170rpx; margin: 0rpx 30rpx"
            ></image>
          </view>
        </view>
        <view class="">
          <image
            src="/static/shopping_add.png"
            class="upload_img"
            @click="uploadimg('company_logo', 1)"
            v-if="company_logo.length != 1"
          />
        </view>
      </view>
    </view>

    <view class="notice">手续费设置%：</view>
    <view class="bootm">
      <input
        class="modal-input"
        type="text"
        v-model="company_fee"
        placeholder="输入收费百分比"
        placeholder-style="font-size:32rpx"
        style="font-size: 32rpx"
        disabled
      />
    </view>

    <u-select v-model="show" :list="list" @confirm="confirm"></u-select>

    <view class="fixed">
      <view class="fixed_button" @click="Submit">保存</view>
    </view>
  </view>
</template>

<script>
import api from "../../api/api";
import tip from "@/utils/tip.js";
import { uploadImage } from "../../utils/upLoad.js";
export default {
  data() {
    return {
      show: false,
      list: [
        {
          value: "1",
          label: "删除",
        },
      ],
      value: "",
      content: "",
      images: [],
      contact: "",
      contact_phone: "",
      fileList: [],
      lengths: 0,
      action: "https://up-z2.qiniup.com/",
      Upimg: [],
      listindex: 0,
      is_select_pic: false,

      //--------
      corporator_name: "",
      upload_arr: "",
      company_name: "",
      company_logo: [],
      MerchantDetail: null,
      company_fee: "",
    };
  },
  onShow() {
    if (this.is_select_pic) {
      return;
    }
    this.getDetail();
  },
  methods: {
    async getDetail() {
      let res = await api.userMerchantDetail({
        method: "get",
        query: {},
        loading: "加载中",
      });

      if (res.code == 0) {
        // 1审核中，2成功，3失败
        this.MerchantDetail = res.data;
        this.company_name = res.data.name;
        this.company_logo = res.data.logo ? JSON.parse(res.data.logo) : [];
        this.company_fee = res.data.commission_rate;
      } else {
        tip.defaults(res.msg);
      }
    },

    // 删除
    remove(index, upload_arr) {
      console.log("------remove", index, upload_arr);
      this.show = true;

      this.listindex = index;
      this.upload_arr = upload_arr;
    },
    // 删除确认
    confirm() {
      this[this.upload_arr].splice(this.listindex, 1);
    },

    // 上传
    async uploadimg(upload_arr, limit) {
      this.is_select_pic = true;

      let res = await uploadImage();
      console.log("--------res", res);
      if (res.length > limit) {
        this[upload_arr] = this[upload_arr].concat(res.slice(0, limit));
      } else {
        this[upload_arr] = this[upload_arr].concat(res);
      }
      if (this[upload_arr].length > limit) {
        this[upload_arr] = this[upload_arr].splice(0, limit);
      }
      console.log("------this[upload_arr]", this["company_logo"]);
    },

    async Submit() {
      if (this.company_name == "") {
        tip.defaults("请输入企业名称");
        return;
      }
      if (this.company_logo.length == 0) {
        tip.defaults("请上传logo");
        return;
      }
      if (this.company_fee == "") {
        tip.defaults("请输入收费百分比");
        return;
      }
      //   if (!/^1[3456789]\d{9}$/.test(this.contact_phone)) {
      //     this.$refs.uToast.show({
      //       title: "请填写正确手机号",
      //       type: "error",
      //     });
      //     return;
      //   }

      let res = await api.userMerchantStore({
        query: {
          logo: this.company_logo,
          commission_rate: this.company_fee,
        },
        method: "post",
      });

      if (res.code == 0) {
        tip.defaults("保存成功");
        setTimeout(() => {
          uni.navigateBack({
            delta: 1, //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
          });
        }, 500);
      } else {
        tip.defaults(res.msg);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../style/yuanchuang.scss";
.whole {
  background-color: $bg-color1;
  min-height: 100vh;
  .input_top {
    color: #bbbbbe;
    height: 100rpx;
    margin-left: 30rpx;
  }
  .input_center {
    color: #ffffff;
    // height: 260rpx;
    padding: 30rpx 0 100rpx;
    margin-left: 30rpx;
    word-break: break-all;
  }
  .input {
    position: relative;
    top: 30rpx;
    background-color: $bg-color3;
    color: #ffffff;
  }
  .upload_upload {
    display: flex;
    align-content: flex-start;
  }
  .upload {
    margin-top: 20rpx;
    background-color: $bg-color3;
    height: 300rpx;
    padding-left: 20rpx;
  }
  .notice {
    margin: 30rpx;
    // width: 160rpx;
    height: 44rpx;
    font-size: 32rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 44rpx;
  }
  .bootm {
    background-color: $bg-color3;
    display: flex;
    align-items: center;
    // padding: 10rpx;
    padding: 30rpx 40rpx;
    .set_name {
      padding: 20rpx 30rpx;
      color: #bbbbbe;
      font-size: 32rpx;
    }
    .modal-input {
      color: #ffffff;
    }
  }
  .button {
    position: relative;
    top: 100rpx;
    margin: 30rpx;
    height: 90rpx;
    color: $text-color4;
    background: $button;
    background-repeat: no-repeat;
    background-size: 100%;
    text-align: center;
    line-height: 90rpx;
    font-size: 32rpx;
    border-radius: 16rpx;
  }
  .upload_img {
    margin-left: 20rpx;
    // margin-top: 10rpx;
    width: 170rpx;
    height: 170rpx;
    // padding: 45rpx;
    background-color: #999999;
  }
}
.fixed {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;

  width: 750rpx;
  height: 130rpx;
  background: #292b2b;
  &_button {
    width: 670rpx;
    height: 90rpx;
    margin: 20rpx auto 0;
    background: $button;
    background-repeat: no-repeat;
    background-size: 100%;

    font-size: 32rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 90rpx;
    text-align: center;
  }
}
.review {
  padding-top: 76rpx;
  width: 530rpx;
  height: 580rpx;
  background: #292b2b;
  border-radius: 22rpx;
  text-align: center;

  &_image {
    width: 300rpx;
    height: 320rpx;
  }
  &_row1 {
    margin-top: 20rpx;
    // width: 160rpx;
    height: 44rpx;
    font-size: 32rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 44rpx;
  }
  &_row2 {
    margin-top: 10rpx;
    // width: 120rpx;
    height: 34rpx;
    font-size: 24rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 34rpx;
  }
}
.fail {
  padding-top: 50rpx;
  text-align: center;
  &_image {
    width: 60rpx;
    height: 60rpx;
  }
  &_row1 {
    margin-top: 14rpx;
    // width: 144rpx;
    height: 50rpx;
    font-size: 36rpx;
    font-weight: 500;
    color: #ffffff;
    line-height: 50rpx;
  }
  &_row2 {
    margin-top: 10rpx;
    // width: 392rpx;
    height: 40rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #1fe7e7;
    line-height: 40rpx;
  }
}
</style>
